package one;

import java.util.ArrayList;
import java.util.List;
import java.util.Random;

public class Exercise {
    private List<Expression> expressions;
    private int count;
    private Random random = new Random();

    // 构造方法：生成指定数量的随机习题
    public Exercise(int count) {
        this.count = count;
        this.expressions = new ArrayList<>();
        for (int i = 0; i < count; i++) {
            expressions.add(generateRandomExpression());
        }
    }

    // 生成单个随机算式（操作数1-100，运算符随机）
    private Expression generateRandomExpression() {
        int num1 = random.nextInt(100) + 1; // 1-100
        int num2 = random.nextInt(100) + 1;
        char[] operators = {'+', '-', '*', '/'};
        char operator = operators[random.nextInt(operators.length)];
        return new Expression(num1, num2, operator);
    }

    // 批量打印习题（带序号）
    public void print() {
        System.out.println("===== 算术习题（共" + count + "道）=====");
        for (int i = 0; i < expressions.size(); i++) {
            System.out.println((i + 1) + ". " + expressions.get(i));
        }
    }

    // 供单元测试获取习题列表
    public List<Expression> getExpressions() {
        return expressions;
    }
}